/**
 * @author 黄波
 * 创建日期：2011Sep 2, 2011
 * TODO// N/A
 */
package com.platform.dev.action;

import java.io.PrintWriter;
import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.platform.dev.bo.DevBo;
import com.platform.pojo.Power;

public class GetPowerAction extends DevSupport {

	private String id;
	private Power power;
	private String msg;
	private boolean success;
	/**
	 * @return the msg
	 */
	public String getMsg() {
		return msg;
	}
	/**
	 * @param msg the msg to set
	 */
	public void setMsg(String msg) {
		this.msg = msg;
	}
	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}
	/**
	 * @return the power
	 */
	public Power getPower() {
		return power;
	}
	/**
	 * @param power the power to set
	 */
	public void setPower(Power power) {
		this.power = power;
	}
	@Override
	public String execute() throws Exception {
		if(id == null || id.equals("")) {
			msg = "加载数据失败，ID为空！";
		} else {
			DevBo bo = new DevBo();
			power = bo.getPower(id);
			if(power == null) {
				msg = "无此数据！";
			}
		}

		success = true;
		HashMap map = new HashMap();
		map.put("power", power);
		map.put("msg", msg);
		map.put("success", success);
		JSONObject json = JSONObject.fromObject(map);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		out.println(json.toString());
		out.flush();
		out.close();
		return null;
	}
	/**
	 * @return the success
	 */
	public boolean isSuccess() {
		return success;
	}
	/**
	 * @param success the success to set
	 */
	public void setSuccess(boolean success) {
		this.success = success;
	}
	
}
